package com.say.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.say.bean.domain.Message;


@Repository
public interface MessageDao extends JpaRepository<Message, String> {
	
	@Query(nativeQuery = true, value = " SELECT * from message t WHERE t.user_id=?1 OR t.to_user_id=?2 ORDER BY t.update_time desc LIMIT 1 ")
	Message getMessageByUserIdAndToUserId(String userId,String toUserId);
	
	@Query(nativeQuery = true, value = "update message set un_read = ?2 ,text=?3 ,update_time=now(),status=1 where id = ?1 ")
	@Modifying
	void saveUnReadMessageById(String id,Integer unRead,String text);
	
	@Query(nativeQuery = true, value = "update message set un_read = 0 where user_id = ?1 and to_user_id=?2 ")
	@Modifying
	void clearUnReadMessageByUser(String userId,String toUserId);
	

}
